package com.xr.hr.care;

import com.xr.common.CommUtil;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.utils.StringHelper;
import com.bstek.dorado.common.*;

/**
 * datasetListener
 */
public class datasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
	  String dsName = dataset.parameters().getString("dsName");
		String sql = "";
			SqlDataset ds = (SqlDataset) dataset;
			DoradoContext context = DoradoContext.getContext();
			 
			if(dsName != null && dsName.equals("batchCreate_datasetEc")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
				 
			}
			if(dsName != null && dsName.equals("change_careCreate_datasetEc")) {
				sql=ds.getSql();
				if(!StringHelper.toValidString(ds.parameters().getString("CARE_MONTH")).equals("")){
					sql+=" and to_char(ec.care_date,'yyyyMM')= '"+ds.parameters().getString("CARE_MONTH")+"' ";
				}
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
				 
			}
			 
			if(dsName != null && dsName.equals("applyList_datasetCareApply")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
				 
			} 
			if(dsName != null && dsName.equals("applyNew_datasetCare")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
				 
			}
			if(dsName != null && dsName.equals("applyNew_datasetCareApply")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
			}
			if(dsName != null && dsName.equals("applyNew_datasetCareApplySum")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
			}
			if(dsName != null && dsName.equals("queryCare_datasetQuery")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
				 
			}
			
    return true;
  }

}
